package com.bltec.emergency.mapper;

import com.bltec.emergency.model.RecordResponse;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RecordResponseMapper {

    //插入一条response记录
    @Insert("insert into record_response (name,response_level,occurred_position,occurred_reason,influence_scope,occurred_time," +
            "casualties,create_by,create_time,enable) " +
            "values(#{name},#{responseLevel},#{occurredPosition},#{occurredReason},#{influenceScope},#{occurredTime},#{casualties}," +
            "#{createBy},#{createTime},#{enable})")
    boolean insert(RecordResponse recordResponse);

    //通过name字段删除Response记录
    @Delete("delete from record_response where name=#{name}")
    boolean deleteByName(String name);

    //通过id设置一条记录为不可用
    @Update("update record_response set enable=0 where id=#{id}")
    boolean setDisableById(Long id);

    //通过id更新一条记录
    @Update("update record_response set name=#{name},occurred_position=#{occurredPosition},occurred_reason=#{occurredPosition}," +
            "influence_scope=#{influenceScope},occurred_time=#{occurredTime},casualties=#{casualties},update_by=#{updateBy},update_time=#{updateTime} where id=#{id}")
    boolean updateResponseById(RecordResponse recordResponse);

    //查找符合name字段的记录
    @Select("select * from record_response where name =#{name} and enable=1")
    RecordResponse getResponseByName(String name);

    //查找符合name字段的记录的id
    @Select("select id from record_response where name =#{name} and enable=1")
    Long getIdByName(String name);

    //查找符合id字段的记录
    @Select("select * from record_response where id =#{id} and enable=1")
    RecordResponse getResponseById(Long id);

    //查找所有记录
    @Select("select * from record_response where enable=1")
    List<RecordResponse> selectAll();
}